﻿Public Class Form1

    Public CurrentWebsite As String ' stores the current website 

    ' a setting is a variable that lasts forever, they are made in the my project form in solution explorer




    Private Sub Previous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Previous.Click
        Me.WebBrowser1.GoBack() ' tells the web browser to go back
    End Sub

    Private Sub Foward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Foward.Click
        Me.WebBrowser1.GoForward() ' tells the web browser to go foward
    End Sub

    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click
        Me.WebBrowser1.Navigate(AddressBar.Text) ' When clicked the url in the address bar is used 
    End Sub

    Private Sub RefreshB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshB.Click
        Me.WebBrowser1.Refresh() ' refreshes webpage
    End Sub

    Private Sub Home_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Home.Click

        Me.WebBrowser1.Url = New Uri(My.Settings.homeurl) ' when home is clicked the url stored in the setting home url is shown

    End Sub


    Private Sub ToolboxWeb_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If My.Settings.FavouritesURL Is Nothing Then
            My.Settings.FavouritesURL = New System.Collections.Specialized.StringCollection
        End If

        If My.Settings.FavouriteName Is Nothing Then
            My.Settings.FavouriteName = New System.Collections.Specialized.StringCollection
        End If

        If My.Settings.homeurl = "" Then ' checks if the setting is empty
            My.Settings.homeurl = ("http://") & InputBox("You must choose a home URL. Dont enter HTTP://") ' uses a input box to get the desired home webpage and adds http:// to it
            Options.HomeURL.Text = My.Settings.homeurl ' shows the new setting in the internet options textbox called Home URL
            AddressBar.Text = My.Settings.homeurl ' displays the contents of the setting in the address bar
        Else
            AddressBar.Text = My.Settings.homeurl ' displays the contents of the setting in the address bar
            WebBrowser1.Url = New Uri(My.Settings.homeurl) ' displays the content of the setting
        End If
    End Sub


    Private Sub Options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InternetOptions.Click
        Options.Show() ' shows the form called options
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        AddressBar.Text = Me.WebBrowser1.Url.ToString ' updates the addressbar with the current website URL
    End Sub

    Private Sub AddressBar_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles AddressBar.KeyDown
        If e.KeyCode = Keys.Enter Then ' when enter is pressed 
            Me.WebBrowser1.Navigate(AddressBar.Text) ' When clicked the url in the address bar is used 
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Input_Favourite.Show()
    End Sub

    Private Sub Minimise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Minimise.Click
        favourites.Visible = False
        WebBrowser1.Height = (704)
        WebBrowser1.Location = New Point(0, 36)
    End Sub

    Private Sub FavouritesTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FavouritesTab.Click
        Dim labelX As Integer = 136
        Dim labelY As Integer = 12


        WebBrowser1.Height = (593)
        WebBrowser1.Location = New Point(0, 170)
        favourites.Visible = True
        
        For i As Integer = 0 To My.Settings.FavouriteName.Count - 1
            Dim Favourite As New Label
            If My.Settings.FavouriteName.Count <> 0 Then
                Favourite.Parent = Tabpage1
                labelX = labelX + 50
                Favourite.Location = New Point(labelX, labelY)
                Favourite.Text = My.Settings.FavouriteName.Item(i)
            End If
        Next

    End Sub

    Private Sub DeleteFav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteFav.Click
        My.Settings.FavouriteName.Clear()
        My.Settings.FavouritesURL.Clear()
        My.Settings.Save()
    End Sub
End Class
